<template>
  <view class="zhibo">
    <iframe allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" :src="dataInfo.link" width="100%" height="100%" frameborder="0"></iframe>
  </view>
</template>

<script lang="ts" setup>
import { roomList } from '@/api/user';
import { getURLParameters, menuJump, wxShare } from '@/utils/tools';
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
onLoad((options:any) => {
  id.value = options.zhibo_id
  getList()
  getJianting()
})
const id = ref(0)
const parme = ref({
  page:1,
  size:10,
  type:0,
  show:1,
})
const dataInfo = ref<Recordable>([])
function getList(){
  uni.showLoading({
    title: '加载中',
    mask: true,
  })
  roomList(parme.value).then((res:any)=>{
    if(res){
      const targetItem = res.find((item: { id: any; }) => Number(item.id) === Number(id.value));
      if (targetItem) {
        dataInfo.value = targetItem;
        wxShare(targetItem, 3);
      } else {
        uni.showToast({
        title: '未找到对应的直播',
        icon: 'none',
        duration: 2000
      })
      setTimeout(()=>{
        uni.navigateBack()
      },1000)
      }
    }else{
      uni.showToast({
        title: '未找到对应的直播',
        icon: 'none',
        duration: 2000
      })
      setTimeout(()=>{
        uni.navigateBack()
      },1000)
    }

    
  })
}
function getJianting(){
    window.addEventListener('message', function (event) {
        // 获取消息内容
        var messageEvent = event.data;
      
        // 打印消息内容
        console.table(messageEvent);
      
        // 检查 messageEvent 是否存在或者是一个对象类型。
        if (!messageEvent || typeof messageEvent !== 'object') {
            // 输出错误信息 'Received invalid message event:'，并将 messageEvent 的值打印出来。
            console.error('Received invalid message event:', messageEvent);
            // 返回（结束当前函数的执行）。
            return;
        }
        // 检查消息类型是否为 "vhOpenHref"，并提取URL
        if (messageEvent.type === 'vhOpenHref' && typeof messageEvent.data === 'string') {
            // 在移动端浏览器上运行的逻辑
            menuJump({is_tab: false,link: '/pages/shop/detail?id='+getURLParameters(messageEvent.data).id,link_type: 1})
            // that.tui.href('/pages/GoodsDetails/GoodsDetails?id='+that.getParam(messageEvent.data,'id'))
            // window.location.href = messageEvent.data;
            // isdetail.value = true
            // detailpopupRef.value?.open(getParam(messageEvent.data,'id'))
        } else {
        
        }
    });
  }
</script>

<style scoped lang="scss">
.zhibo{width: 100vw;height: 100vh;}
</style>